package com.wnxy.sddfp.payback.job;

import com.wnxy.sddfp.payback.service.IBorrowerPayPlanService;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@Component
public class PayJob {

    @Autowired
    private IBorrowerPayPlanService borrowerPayPlanService;

    /**
     * 分片广播任务
     */
    @XxlJob("payBackJobHandler")
    public void shardingJobHandler() throws Exception {

        // 分片参数
        int shardIndex = XxlJobHelper.getShardIndex();
        int shardTotal = XxlJobHelper.getShardTotal();

        String today = LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE);
        borrowerPayPlanService.doRepay(today,shardIndex,shardTotal);
    }
}
